<?php
// +----------------------------------------------------------------------
// | Author: 发仔 <i@fazi.me> 
// +----------------------------------------------------------------------

namespace app\admin\controller;

use think\Controller;
use think\Db;
use think\Cache;

class Models extends Base
{
	protected $id = 'car_type_id';
	protected $table = 'CarType';
	
	//通用选项
	protected function parseData($data = []) {
		
		$data['car_type_name'] = config('base.types')[$data['type']].config('base.car_types')[$data['car_type']];
		
		//除中大小包外，无座位
		if(in_array($data['car_type'],[5,6,7])) {
			$data['car_type_name'] .= "({$data['seats']}座)";
		} else {
			$data['seats'] = 0;
		}
		if($data['chartered_hour']) {
			$data['car_type_name'] .= "-{$data['chartered_hour']}小时";
		}
		return $data;
		
	}
	
	//搜索
	protected function search($item = []) {
		
		$P = input('param.');
		$where = [];
		
		$P['type'] && $where['type'] = $P['type'];
		$P['car_type'] && $where['car_type'] = $P['car_type'];
		
		if( $this->user['official'] && !in_array($where['type'],[2,3])  ){
			$where['type'] = 2;
		}
		
		return $where;
		
	}
	
	
	protected function options($item = []) {
		
		$types = config('base.types');
		$car_types = config('base.car_types');
		
		if( $this->user['official'] ){
			unset($types[4]);
			unset($types[5]);
		}
		
		//
		$this->assign('types',TplOptions($types,$item['type']?:$item['m.type']));
		$this->assign('car_types',TplOptions($car_types,$item['car_type']?:$item['m.car_type']));
		
		return $item;
	}
	
}
